package com.pine.app.module.security.core.authorize.metadataSource;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author xiaoyuan
 * @create 2020/3/23
 **/
public enum PermissionType {

    PERMS("perms"),ROLE("role"),
    ANON("anon"),PORT("port"),
    AUTHCBASIC("authcBasic"),
    SCOPE("scope"),
    SSL("ssl");
    static final Map<String, PermissionType> codeMapping = Arrays.stream(PermissionType.values())
            .collect(Collectors.toMap(PermissionType::getCode, type -> type));

    private String code;

    PermissionType(String code){
        this.code = code;
    }

    public String getCode() {
        return code;
    }

    public static Optional<PermissionType> fromName(String code) {
        return Optional.ofNullable(codeMapping.get(code));
    }
}
